﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Invent
{
    public partial class frmSetupForm : Form
    {
        private Settings set;
        public frmSetupForm()
        {
            InitializeComponent();
            set = new Settings();
            try
            {
                set.ReadFromFile();

            }
            catch
            {
                MessageBox.Show("Ошибка чтения конфигурации", "Ошибка", 
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                txtServer.Text = set.Server;
                txtPort.Text = set.Port;
                txtDataBase.Text = set.Database;
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void frmSetupForm_Shown(object sender, EventArgs e)
        {

        }

        private void btnSaveSettings_Click(object sender, EventArgs e)
        {
            set.Server = txtServer.Text;
            set.Port = txtPort.Text;
            set.Database = txtDataBase.Text;
            set.SaveToFile();
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
